package org.foreveross.koala.jbpm.util;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

import org.foreveross.koala.jbpm.wsclient.JBPMApplication;
import org.foreveross.koala.jbpm.wsclient.JBPMApplicationImplService;

public class WSClient {

	private static Map<String,JBPMApplication> services = new HashMap<String,JBPMApplication>();
	
	public static JBPMApplication getJBPMApplication(String wsdl){
		if(services.containsKey(wsdl)){
			return services.get(wsdl);
		}
		else{
			 URL url = null;
		        try {
		            URL baseUrl;
		            baseUrl = org.foreveross.koala.jbpm.wsclient.JBPMApplicationImplService.class.getResource(".");
		            url = new URL(baseUrl,wsdl);
		        } catch (MalformedURLException e) {
		        	e.printStackTrace();
		        }
		    JBPMApplicationImplService service = new JBPMApplicationImplService(url);
		    JBPMApplication application = service.getJBPMApplicationImplPort();
		    services.put(wsdl, application);
		    System.out.println(application.getProcesses());
			return application;
		}
	}
	
	public static void main(String args[]){
		String url = "http://localhost/jbpm/jbpmService?wsdl";
		JBPMApplication application = WSClient.getJBPMApplication(url);
		
	}
}
